import config from '../config'

function checkStatus(response) {
  if (response.status >= 200 && response.status < 300) {
    return response;
  }
  const error = new Error(response.statusText);
  error.response = response;
  throw error;
};
export default async (url, dt) => {
  if (url.indexOf('22222') === -1) {
    url = config.host + url
  }

  console.log(url, "API request --", dt)
  const response = await fetch(url, { method: "POST", body: JSON.stringify(dt) });
  checkStatus(response);
  const res = await response.json();
  console.log(url, "API return  --", res)
  return res;
};
